﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:personalplaner.common.controls"
                    xmlns:conv="clr-namespace:personalplaner.common.converters"
                    xmlns:k="clr-namespace:personalplaner.common.themes">

    <!-- 
    *****************************************************************
    ToggleButton for CollapsiblePanel Theme 
    *****************************************************************
    -->

    <!--<conv:BoolInvertConverter x:Key="boolInvert"/>-->
    
    <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
        <Border Name="Border" Background="Transparent" Margin="5">

            <Path SnapsToDevicePixels="True" IsHitTestVisible="False" Name="Arrow" Fill="#0FFF" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Right" VerticalAlignment="Center" Data="M 5 0 L 5 8 L 0 4 Z" Stroke="{DynamicResource {x:Static k:ResourceKeys.GlyphBrush}}" StrokeThickness="0.5">
                <Path.RenderTransform>
                    <RotateTransform Angle="0" />
                </Path.RenderTransform>
            </Path>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="False">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" To="-90" DecelerationRatio="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation  Storyboard.TargetName="Arrow" Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)" Duration="0:0:0.2" AccelerationRatio="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="#81F5F5F5"/>
                <Setter TargetName="Arrow" Property="Fill" Value="#81F5F5F5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- 
    *****************************************************************
    CollapsiblePanel Template 
    *****************************************************************
    -->

    <Style TargetType="Expander" x:Key="ItemExpander">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Name="ContentRow" Height="0"/>
                        </Grid.RowDefinitions>
                        <Border Name="Border" Grid.Row="0" Background="Transparent" >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" />
                                <ToggleButton Margin="8,0,4,0" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" />

                            </Grid>
                        </Border>

                        <Border Grid.Row="1" BorderThickness="0.5,1,0,0" BorderBrush="#6000" Background="#10FFFFFF" CornerRadius="2,3,2,2" HorizontalAlignment="Stretch" SnapsToDevicePixels="True" Margin="2,2,5,6" >
                            <Border BorderThickness="0,0,1,1" BorderBrush="#20FFFFFF" CornerRadius="2,3,2,2" Padding="5" HorizontalAlignment="Stretch">
                                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                    <ContentPresenter ContentSource="Content" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Stretch"/>
                                </ScrollViewer>
                            </Border>
                        </Border>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="False">
                            <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content, Path=DesiredHeight}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="#81F5F5F5"/>
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="Border" Property="IsMouseOver" Value="True" />
                                <!--<Condition Property="IsExpanded" Value="False" />-->
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                            <Setter TargetName="Border" Property="Cursor" Value="Hand" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type local:CollapsibleItem}">
        <Setter Property="DockPanel.Dock" Value="Top"/>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CollapsibleItem}">
                    <Expander Style="{StaticResource ItemExpander}" 
                              IsExpanded="{Binding Path=IsCollapsed, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                              Header="{Binding Header, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                              HeaderTemplate="{TemplateBinding HeaderTemplate}">
                        <ContentPresenter/>
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type local:CollapsibleItem}" x:Key="TheOriginalUsingReveal">
        <Setter Property="DockPanel.Dock" Value="Top"/>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:CollapsibleItem}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Name="ContentRow" Height="0"/>
                        </Grid.RowDefinitions>
                        <Border Name="Border" Grid.Row="0" Background="Transparent" >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>

                                <ContentPresenter Margin="4" ContentSource="Header" RecognizesAccessKey="True" />
                                <ToggleButton Margin="8,0,4,0" IsChecked="{Binding Path=IsCollapsed,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" />

                            </Grid>
                        </Border>
                        
                        <local:Reveal x:Name="ContentReveal" Grid.Row="1" VerticalReveal="FromTopToBottom" HorizontalReveal="None">
                            <!-- the extra border here is required because Reveal doesn't account for margins -->
                            <!--<Border>
                                <ContentPresenter Grid.Row="1" ContentSource="Content" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>-->

                            <Border BorderThickness="0.5,1,0,0" BorderBrush="#6000" Background="#10FFFFFF" CornerRadius="2,3,2,2" HorizontalAlignment="Stretch" SnapsToDevicePixels="True" Margin="0,0,5,6" ><!--Width="200"-->
                                <Border BorderThickness="0,0,0.5,1" BorderBrush="#20FFFFFF" CornerRadius="2,3,2,2" Padding="5" HorizontalAlignment="Stretch">
                                    <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
                                        <ContentPresenter ContentSource="Content" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="Stretch"/>
                                    </ScrollViewer>
                                </Border>
                            </Border>

                        </local:Reveal>
                        
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsCollapsed" Value="False">
                            <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}" />
                            <!--<Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content, Path=ActualHeight}" />-->
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="#81F5F5F5"/>
                        </Trigger>


                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="Border" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsCollapsed" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Border" Property="Background" Value="#20FFFFFF" />
                            <Setter TargetName="Border" Property="Cursor" Value="Hand" />
                        </MultiTrigger>
                        <Trigger Property="IsCollapsed" Value="False">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation BeginTime="0:0:0.2"  Storyboard.TargetName="ContentReveal" Storyboard.TargetProperty="AnimationProgress" Duration="0:0:0.2" To="1" DecelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentReveal" Storyboard.TargetProperty="AnimationProgress" Duration="0:0:0.2" AccelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>